package com.gift.recommendation.modules.user.biz;

import com.gift.recommendation.modules.user.dto.ProvinceReq;
import com.gift.recommendation.modules.user.dto.ProvinceExt;
import com.gift.recommendation.modules.user.dto.ProvinceRsp;
import com.gift.recommendation.modules.user.service.ProvinceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zzh <2658137258@qq.com>
 * @date 2023/2/16
 */
@Service
public class ProvinceBiz {
    @Autowired
    private ProvinceService provinceService;

    public ProvinceRsp getListProvince() {
        ProvinceRsp provinceRsp = new ProvinceRsp();
        List<ProvinceExt> list = provinceService.getListProvince();
        provinceRsp.setList(list);
        provinceRsp.setHaveCity(false);
        return provinceRsp;
    }

    public ProvinceRsp getlistCity(ProvinceReq req) {
        ProvinceRsp provinceRsp = new ProvinceRsp();
        Integer haveCity = provinceService.haveCity(req);
        if (haveCity > 1){
            provinceRsp.setHaveCity(false);
            List<ProvinceExt> list = provinceService.getListCity(req);
            provinceRsp.setList(list);
            return provinceRsp;
        }else{
            provinceRsp.setHaveCity(true);
            return provinceRsp;
        }
    }

    public ProvinceRsp getListArea(ProvinceReq req) {
        ProvinceRsp provinceRsp = new ProvinceRsp();
        List<ProvinceExt> list = provinceService.getListArea(req);
        provinceRsp.setList(list);
        provinceRsp.setHaveCity(false);
        return provinceRsp;
    }

    public ProvinceRsp getListTown(ProvinceReq req) {
        ProvinceRsp provinceRsp = new ProvinceRsp();
        List<ProvinceExt> list = provinceService.getListTown(req);
        provinceRsp.setList(list);
        provinceRsp.setHaveCity(false);
        return provinceRsp;
    }
}
